package com.omp.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.omp.common.action.Struts2ActionSupport;
import com.omp.entity.UserLevel;
import com.omp.service.UserLevelService;

@SuppressWarnings("serial")
@Namespace("/userlevel")
@Results({
	@Result(name = Struts2ActionSupport.RELOAD, type = "redirect", location = "user_level.action")
})
public class UserLevelAction extends Struts2ActionSupport<UserLevel> {
	
	private Integer id; //产品ID
	private UserLevel userLevel = new UserLevel();
	private Page<UserLevel> page = new Page<UserLevel>(10);
	private List<Integer> ids;
	
	@Autowired
	private UserLevelService userLevelService;
	
	@Override
	public String list() throws Exception {
		page = userLevelService.findByPage(page, userLevel);
		return "list";
	}
	
	@Override
	protected void prepareModel() throws Exception {
		if (id != null) {
			userLevel = userLevelService.findById(id);
		}
	}
	
	@Override
	public UserLevel getModel() {
		return userLevel;
	}
	
	public String input() {
		return "input";
	}
	
	public String save() {
		userLevelService.save(userLevel);
		return RELOAD;
	}
	
	public String update() {
		userLevelService.update(userLevel);
		return RELOAD;
	}
	
	public String delete() {
		userLevelService.delete(id);
		return RELOAD;
	}
	
	public String batchDelete() {
		userLevelService.batchDelete(ids);
		return RELOAD;
	}
	
	public void nameExists() {
		Struts2Utils.renderJson(userLevelService.nameExists(userLevel.getLevelName()));
	}
	public UserLevel getUserLevel() {
		return userLevel;
	}
	public void setUserLevel(UserLevel userLevel) {
		this.userLevel = userLevel;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Page<UserLevel> getPage() {
		return page;
	}
	public void setPage(Page<UserLevel> page) {
		this.page = page;
	}

	public void setIds(List<Integer> ids) {
		this.ids = ids;
	}
}
